/**
 * 结算场景
 */
class OverScreen extends egret.DisplayObjectContainer {
    /** 加载背景 */
    private bg_png: egret.Bitmap = Main.createBitmapByName("bg_1_png");
    /** 创建按钮组容器 */
    private btnContainer: egret.Sprite = new egret.Sprite();
    /** 加载二维码 */
    private erweima_png = Main.createBitmapByName("erweima_png");
    public constructor() {
        super();
        this.once(egret.Event.ADDED_TO_STAGE, this.init, this);
    }

    private init() {
        this.addChild(this.bg_png);
        this.createChenghao();
        this.btnContainerSetting();
        this.createSaveBtn();
        this.createFenxiangBent();
        this.createErweima();
    }
    /** 添加称号图片 */
    private createChenghao() {
        const chenghao_png: egret.Bitmap = Main.createBitmapByName("chenghao_png");
        this.addChild(chenghao_png);
        Main.anchorCenter(chenghao_png);
        chenghao_png.x = this.stage.stageWidth * .5;
        chenghao_png.y = this.stage.stageHeight * .5;
    }
    /** 按钮容器设置 */
    private btnContainerSetting() {
        this.addChild(this.btnContainer);
        this.btnContainer.x = 550;
        this.btnContainer.y = 424;
    }
    /** 添加保存按钮 */
    private createSaveBtn() {
        const btn_png = Main.createBitmapByName("save_btn_png");
        this.btnContainer.addChild(btn_png);
        btn_png.touchEnabled = true;
        btn_png.addEventListener(egret.TouchEvent.TOUCH_TAP, btnTouchHandler, this);

        function btnTouchHandler(evt: egret.TouchEvent) {
            egret.Tween.get(this.btnContainer)
                .to({ alpha: 0 })
                .call(() => {
                    this.erweima_png.alpha = 1;
                    Main.shareImage(this);
                })
                .to({ alpha: 1 })
                .call(() => {
                    this.erweima_png.alpha = 0;
                });
        }
    }
    /** 添加二维码 */
    private createErweima() {
        this.addChild(this.erweima_png);
        this.erweima_png.x = 630;
        this.erweima_png.y = 414;
        this.erweima_png.alpha = 0;
    }
    /** 添加分享按钮 */
    private createFenxiangBent() {
        const btn_png = Main.createBitmapByName("fenxiang_btn_png");
        this.btnContainer.addChild(btn_png);
        btn_png.x = this.btnContainer.width + 100;
        btn_png.touchEnabled = true;
        btn_png.addEventListener(egret.TouchEvent.TOUCH_TAP, btnTouchHandler, this);

        function btnTouchHandler(evt: egret.TouchEvent) {
            this.createFenxiangMask();
        }
    }
    /** 创建分享提示遮罩层 */
    private createFenxiangMask() {
        const fenxiang_png = Main.createBitmapByName("fenxiang_png");
        this.addChild(fenxiang_png);

        fenxiang_png.touchEnabled = true;
        fenxiang_png.addEventListener(egret.TouchEvent.TOUCH_TAP, maskTouchHandler, this);

        function maskTouchHandler(evt: egret.TouchEvent) {
            this.removeChild(fenxiang_png);
        }
    }
}